const {AppletBikeCollect} = require('../db/seq')

class AppletBikeCollectServe {
    async updateBikeCollectStatusServe(bikeId, userId) {
        const res = await AppletBikeCollect.create({
            bikeId,
            userId
        })
        console.log(res);
    }

    async getCollectByUserIdServe({bikeId, userId, isAll}) {
        let whereOpt = {}
        bikeId && Object.assign(whereOpt, {bikeId})
        userId && Object.assign(whereOpt, {userId})
        let res;
        if (isAll) {
            res = await AppletBikeCollect.findAll({
                where: whereOpt
            })
        } else {
            res = await AppletBikeCollect.findOne({
                where: whereOpt
            })
        }
        return res
    }

    async deleteCollectByUserIdServe(bikeId, userId) {
        const res = await AppletBikeCollect.destroy({
            where: {
                bikeId,
                userId
            }
        })
        console.log(res);
        return res[0] > 0
    }
}

module.exports = new AppletBikeCollectServe()
